﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="/lib/signalr/signalr.js"></script>
    <script src="/lib/jquery/dist/jquery.js"></script>
</head>
<body>
    <ul id="ulist"></ul>
    <div id="msg"></div>
    组名：  <input type="text" id="groupName" /><button id="btnGroup">加入Group</button><br />
    组名：  <input type="text" id="gName" /><input type="text" id="groupContent" /><button id="btnSendGroup">发送Group内容</button><br />
    <script>
        var connection = new signalR.HubConnectionBuilder().withUrl("/groupHub").build();

        connection.on("onMessage", function (msg) {
            $("<li>msg:" + msg + "</li>").appendTo($("#ulist"));
        });

        connection.on("onMessage1", function (msg) {
            $("<li>msg1:" + msg + "</li>").appendTo($("#ulist"));
        });

        connection.start().catch(function (err) {
            return console.error(err.toString());
        });

        $("#btnGroup").click(function () {
            var groupName = $("#groupName").val();
            connection.invoke("addGroupAsync", groupName).catch(function (err) {
                return console.error(err.toString());
            });;
        });

        $("#btnSendGroup").click(function () {
            var gName = $("#gName").val();
            var groupContent = $("#groupContent").val();
            connection.invoke("sendGroupMsgAsync", gName, groupContent).catch(function (err) {
                return console.error(err.toString());
            });;
        });
    </script>

</body>
</html>
